package com.zc.study;

import com.fasterxml.jackson.core.util.InternCache;
import com.fasterxml.jackson.databind.util.ObjectIdMap;

import java.util.*;

public class Test {
    /**
     * {
     *     3,4
     *     3,2
     *     4,5
     *     2,7
     *     9,6
     * }
     * 输出
     * 3
     *   4
     *     5
     *   2
     *     7
     * 9
     *   6
     *
     *
     */

    public  static void setData(int[][] arr){
        Map<Integer,List<Integer>> map = new HashMap();
        Set set = new HashSet<Integer>();
        List<Integer> list = null;
        for(int[] i: arr){
            set.add(i[1]);
            if(map.containsKey(i[0])){
                map.get(i[0]).add(i[1]);
            }else{
                list = new ArrayList();
                list.add(i[1]);
                map.put(i[0],list);
            }
        }
        map.forEach((k,v)->{
            if(!set.contains(k)){
                System.out.println(k);
                showData(k,map);
            }
        });

    }

    public static  String string = "";

    public static void showData(int a,Map<Integer,List<Integer>> map){
        if(map.get(a) != null){
            List<Integer> integers = map.get(a);
            integers.forEach((k)->{
                string +="-";
                System.out.println(string+k);
                showData(k,map);
            });
        }else{
            string = "";
        }
    }

    public static void main(String[] args) {
        int[][] arr = {{3,4},{3,2},{4,5},{2,7},{9,6}};
        setData(arr);
    }
}
